
#include "main.h"

int t4 = 0;

#ifdef USE_LCD

void interrupt4(void)
{
	t4++;
	if(t4==100) {
		LCD_Refresh();
		t4 = 0;
	}
	TIM4_ClearITPendingBit(TIM4_IT_UPDATE); //清中断标志位
}

#else

void interrupt4(void)
{
	t4++;
	
	if (t4==1){
		GPIO_WriteLow(SEG_PORT, SEG_SEL1);
		GPIO_WriteHigh(SEG_PORT, SEG_SEL2);
		GPIO_WriteHigh(SEG_PORT, SEG_SEL3);
	
		switch(mode) {
			case MODE_OFFSET_BEGIN:
				send_byte(SHOW_OFFSET_BEGIN>>16);
				break;
			case MODE_OFFSET_SET:
				if (offset_positive)
					send_byte(0x00);
				else
					send_byte(0x02);  // "-"
				break;
			case MODE_PID_BEGIN:
				send_byte(SHOW_PID_BEGIN>>16);
				break;
			case MODE_ALERT_BEGIN:
				send_byte(SHOW_ALERT_BEGIN>>16);
				break;
			case MODE_TI_BEGIN:
				send_byte(SHOW_TI_BEGIN>>16);
				break;
			case MODE_PWM_BEGIN:
				send_byte(SHOW_PWM_BEGIN>>16);
				break;
			case MODE_DEFAULT:
				send_byte(SHOW_DEFAULT>>16);
				break;
			case MODE_LOCK_BEGIN:
				send_byte(SHOW_LOCK_BEGIN>>16);
				break;
			case MODE_PWM_SET:
			case MODE_ALERT_SET:
				send_byte(0x00);
				break;
			case MODE_SHUTDOWN:
				send_byte(0x02);  // -
				break;
			default:
				if (show_value < 0)
					send_byte(0x02);  // "-"
				else
					send_num(show_value/100);
				break;
		}
	 	
	}else
	
	if (t4==(1+REFRESH)){
		GPIO_WriteHigh(SEG_PORT, SEG_SEL1);
		GPIO_WriteLow(SEG_PORT, SEG_SEL2);
		GPIO_WriteHigh(SEG_PORT, SEG_SEL3);
		switch(mode) {
			case MODE_OFFSET_BEGIN:
				send_byte((SHOW_OFFSET_BEGIN>>8)%256);
				break;
			case MODE_PID_BEGIN:
				send_byte((SHOW_PID_BEGIN>>8)%256);
				break;
			case MODE_ALERT_BEGIN:
				send_byte((SHOW_ALERT_BEGIN>>8)%256);
				break;
			case MODE_TI_BEGIN:
				send_byte((SHOW_TI_BEGIN>>8)%256);
				break;
			case MODE_PWM_BEGIN:
				send_byte((SHOW_PWM_BEGIN>>8)%256);
				break;
			case MODE_DEFAULT:
				send_byte((SHOW_DEFAULT>>8)%256);
				break;
			case MODE_LOCK_BEGIN:
				send_byte((SHOW_LOCK_BEGIN>>8)%256);
				break;
			case MODE_SHUTDOWN:
				send_byte(0x02);
				break;
			case MODE_PWM_SET:
			case MODE_PID_SET:
			case MODE_TI_SET:
				send_num((show_value/10)%10);
				break;
			default:
				send_num_dp((show_value/10)%10);
				break;
		}
	}else
	
	if (t4==(1+REFRESH*2)){
		GPIO_WriteHigh(SEG_PORT, SEG_SEL1);
		GPIO_WriteHigh(SEG_PORT, SEG_SEL2);
		GPIO_WriteLow(SEG_PORT, SEG_SEL3);
		switch(mode) {
			case MODE_OFFSET_BEGIN:
				send_byte(SHOW_OFFSET_BEGIN%256);
				break;
			case MODE_PID_BEGIN:
				send_byte(SHOW_PID_BEGIN%256);
				break;
			case MODE_ALERT_BEGIN:
				send_byte(SHOW_ALERT_BEGIN%256);
				break;
			case MODE_PWM_BEGIN:
				send_byte(SHOW_PWM_BEGIN%256);
				break;
			case MODE_TI_BEGIN:
				send_byte(SHOW_TI_BEGIN%256);
				break;
			case MODE_DEFAULT:
				send_byte(SHOW_DEFAULT%256);
				break;
			case MODE_LOCK_BEGIN:
				send_byte(SHOW_LOCK_BEGIN%256);
				break;
			case MODE_SHUTDOWN:
				send_byte(0x02);
				break;
			case MODE_SET_TEMP:
			case MODE_OFFSET_SET:
			case MODE_PID_SET:
			case MODE_TI_SET:
			case MODE_ALERT_SET:
			case MODE_PWM_SET:
			case MODE_OHM_SET:
				// 最后一位闪烁
				if (bling & (up_cnt<5) & (down_cnt<5))
					send_byte(0x00);
				else
					send_num(show_value%10);
				break;
			default:
				send_num(show_value%10);
				break;
		}
	}else
	
	if (t4==(REFRESH*3)){
		t4 = 0;
	}
	
	TIM4_ClearITPendingBit(TIM4_IT_UPDATE); //清中断标志位
}

#endif
